/**
 * @class common.utils.home
 * 一些函数集
 * @singleton
 */
define(function (require) {
    var utils = require('common/utils');
    var Mask = require('common/mask');
    var mask = new Mask();

    return _.extend(utils, {
        ajaxGet: function (params, success, error) {
            utils._ajaxGet(params, function (resp, request) {
                if (_.empty(success)) {
                }
                else {
                    success.apply(this, [resp, request]);
                }
            }, function (resp, request) {
                if (_.empty(error)) {
                    mask.error(resp.msg, function () {
                        if (resp.url) {
                            window.location.href = resp.url;
                        }
                    });
                    if (resp.exception) {
                        console.error(_.sprintf("服务器异常信息：\n%s", JSON.stringify(resp.exception, null, 2)));
                    }
                }
                else {
                    mask.hide();
                    error.apply(this, [resp, request]);
                }
            });
        },
        ajaxPost: function (params, success, error) {
            utils._ajaxPost(params, function (resp, request) {
                mask.hide();
                if (_.empty(success)) {
                    console.log(resp);
                }
                else {
                    success.apply(this, [resp, request]);
                }
            }, function (resp, request) {
                if (_.empty(error)) {
                    mask.error(resp.msg);

                    if (resp.url) {
                        window.location.href = resp.url;
                    }
                    if (resp.exception) {
                        console.error(_.sprintf("服务器异常信息：\n%s", JSON.stringify(resp.exception, null, 2)));
                    }
                }
                else {
                    mask.hide();
                    error.apply(this, [resp, request]);
                }
            });
        }
    });
});